package com.pjedu.springbootrabbitmqproduce08.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 汪洋
 * @Description
 */
@Configuration
public class RabbitMQConfig {
    public static final String SPRINGBOOT_TOPIC_EXCHANGE_NAME="boot_topic_exchangeName";
    private static final String QUEUE_EXCHANGE_NAME_ONE = "boot_queue1";
    private static final String QUEUE_EXCHANGE_NAME_TWO = "boot_queue2";
    //定义一个交换机
    @Bean
    public Exchange createExchange() {
        return ExchangeBuilder.topicExchange(SPRINGBOOT_TOPIC_EXCHANGE_NAME).durable(true).build();
    }

    //定义两个队列
    @Bean("bootQueue1")
    public Queue createQueue1(){
        return QueueBuilder.durable(QUEUE_EXCHANGE_NAME_ONE).build();
    }
    @Bean("bootQueue2")
    public Queue createQueue2(){
        return QueueBuilder.durable(QUEUE_EXCHANGE_NAME_TWO).build();
    }

    //进行交换机和队列的绑定
    @Bean
    public Binding bindQueueAndExchange1(Exchange exchange,@Qualifier("bootQueue1") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("#.user").noargs();
    }
    @Bean
    public Binding bindQueueAndExchange2(Exchange exchange,@Qualifier("bootQueue2") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("insert.#").noargs();
    }
}
